package com.game.tiledmap;

import java.util.LinkedList;

import com.game.framwork.itf.Graphics;

public class DamgeReceiveManager {
	public LinkedList<DamgeReceive> listDame;
	private static DamgeReceiveManager damgeManager = null;
	
	public static DamgeReceiveManager getInstance() {
		if (damgeManager == null) {
			damgeManager = new DamgeReceiveManager();
		}
		return damgeManager;
	}
	
	DamgeReceiveManager() {
		listDame = new LinkedList<DamgeReceive>();
	}
	
	private int isHadDamgeSlot() {
		int count = listDame.size();
		if (count <= 0) {
			return -1;
		}
		for (int i = 0; i < count; i++) {
			if (!listDame.get(i).isActive) {
				return i;
			}
		}
		return -1;
	}
	
	public void addDameReceive(DamgeReceive damgeReceive) {
		int index = isHadDamgeSlot();
		if (index == -1) {
			DamgeReceive dame = damgeReceive;
			listDame.add(dame);
		} else {
			listDame.get(index).isActive = true;
			listDame.get(index).dame = damgeReceive.dame;
			listDame.get(index).x = damgeReceive.x;
			listDame.get(index).y = damgeReceive.y;
		}
	}
	
	public void update(float deltaTime) {
		for (DamgeReceive damgeReceive : listDame) {
			if (damgeReceive.isActive) {
				damgeReceive.update(deltaTime);
			}
		}
	}
	
	public void paint(Graphics g) {
		for (DamgeReceive damgeReceive : listDame) {
			if (damgeReceive.isActive) {
				damgeReceive.paint(g);
			}
		}
	}

	public void clear() {
		listDame.clear();
	}
}
